package PL.prac1;
import java.io.StringWriter;
import java.util.Scanner;


public class campos {

	
	public String Translatefront (String front) {
		String to = null;
		String date = null;
		String where = null;
		String why = null;
		Scanner reader = new Scanner (front);
		//to
		reader.useDelimiter("<to>");
		reader.next();
		reader.useDelimiter("</to>");
		to = reader.next();
		to = to.replace ("<to>", "");
		//date
		reader.useDelimiter("<date>");
		reader.next();
		reader.useDelimiter("</date>");
		date = reader.next();
		date = date.replace ("<date>", "");
		//where
		reader.useDelimiter("<where>");
		reader.next();
		reader.useDelimiter("</where>");
		where = reader.next();
		where = where.replace ("<where>", "");
		//why
		reader.useDelimiter("<why>");
		reader.next();
		reader.useDelimiter("</why>");
		why = reader.next();
		why = why.replace ("<why>", "");
		reader.close();
		StringWriter aux = new StringWriter();
		aux.write("<P><TABLE>\n<TBODY>\n");
		aux.write("<TR><TD class=\"front\"><font color=\"orange\">To: </font></TD>\n<TD><font color=\"orange\">" + to + "</font></TD></TR>\n");
		aux.write("<TR><TD class=\"front\"><font color=\"red\">When: </font></TD>\n<TD><font color=\"red\">" + date + "</font></TD></TR>\n");
		aux.write("<TR><TD class=\"front\"><font color=\"green\">Venue: </font></TD>\n<TD><font color=\"green\">" + where + "</font></TD></TR>\n");
		aux.write("<TR><TD class=\"front\"><font color=\"pink\">Occasion: </font></TD>\n<TD><font color=\"pink\">" + why + "</font></TD></TR>\n");
		aux.write("</TBODY>\n</TABLE>\n");
		return aux.toString();
	}
		
	public String TranslateBody(String body) {
		body = body.replace ("<body>","");
		body = body.replaceAll("<par>", "<P><font color=\"purple\">");
		body = body.replaceAll("</par>", "</P></font>");
		body = body.replaceAll("<emph>", "<EM><font color=\"red\">");
		body = body.replaceAll("</emph>", "</EM></font>");
		return body;
	}
	
	public String TranstaleBack(String back) {
		String signature;
		Scanner scanner = new Scanner(back);
		scanner.useDelimiter("<signature>|</signature>");
		scanner.next();
		signature = scanner.next();
		scanner.close();
		StringWriter aux = new StringWriter();
		//aux.write("<P>");
		aux.write("<P CLASS=\"signature>\"><font color=\"blue\">");
		aux.write(signature);
		aux.write("</font></P>\n");
		return aux.toString();
	}
}
